package cn.gson.crmdemo.controller.finance;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.service.FkfpService;
import cn.gson.crmdemo.model.vo.FkkpjlVo;

@Controller
public class FkfpController {
	@Autowired
	FkfpService fs;
	public Map<String,Object> yy(JSONArray selectfkfp,Page page) {
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("list",selectfkfp);
		map.put("total",page.getTotal());
		return map;
	}
	@RequestMapping("fkfp")
	@ResponseBody
	public Map<String,Object>fkfp(Integer pageNum,Integer pasgeSize,String piDate,String piPhone,Integer piYnpay){
		//分页
		
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=fs.fkfp(piDate,piPhone,piYnpay);
		//创建Map集合
		return this.yy(selectfkfp, page);
		
	}
	@RequestMapping("addfkfp")

	public String addfkfp(FkkpjlVo fo) {
		fs.addfkfp(fo);
		return "redirect:fkfp?pageNum=1&pasgeSize=7";
	}
	//模糊时间查询
	@RequestMapping("fkfp-sj")
	@ResponseBody
	public Map<String,Object>selectsj(Integer pageNum,Integer pasgeSize,String rq){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=fs.selectsj("%"+rq+"%");
		//创建Map集合
		return this.yy(selectfkfp, page);
	}
	//模糊发票号查询
	@RequestMapping("fkfp-fph")
	@ResponseBody
	public Map<String,Object>selectfph(Integer pageNum,Integer pasgeSize,String fph){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=fs.selectfph("%"+fph+"%");
		//创建Map集合
		return this.yy(selectfkfp, page);
	}
	
	@RequestMapping("fkfp-fkfs")
	@ResponseBody
	public Map<String,Object>selectfs(Integer pageNum,Integer pasgeSize,Integer q){
		//分页
		
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selectfkfp=fs.selectfs(q);
		//创建Map集合
		return this.yy(selectfkfp, page);
	}
	
}
